package com.example.springbootmybatis.config;


import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Jimmy Li
 * @version : v1.0.0
 * @Package : cn.mcd.b2c.member.config
 * @Description : SwaggerConfiguration
 * @Create on : 2020/8/19 11:49
 **/

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {

    @Value("${swagger.host}")
    private String swaggerHost;

    @Bean
    public Docket createRestApi() {
        //设置请求头信息
        ParameterBuilder accessToken = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        accessToken.name("accessToken").description("企业会员通网关认证信息")
                .modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build();
        pars.add(accessToken.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .host(swaggerHost)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.springbootmybatis.web"))
                .build()
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("[member-service]")
                .description("麦当劳企业会员通服务")
                .version("0.0.1")
                .build();
    }
}